package com.foreveross.taskservice.infra.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;



public class StringUtils extends org.apache.commons.lang3.StringUtils {

	public static String trimEmpty(String str){
		return StringUtils.isNotBlank(str) ? str.trim() : "";
	}
	private static Pattern p = Pattern.compile("\\s*|\t|\r|\n");
	public static String replaceBlank(String str) {
        String dest = null;
            Matcher m = p.matcher(str);
            dest = m.replaceAll("");
        return dest;
    }

	/**
	 * 将一个集合字符串，按逗号组装出一个字符串
	 * @param list
	 * @return
	 */
	public static String compList(List<String> list){
		return StringUtils.compList(list, ",");
	}
	/**
	 * 将一个集合字符串，按指定分隔符组装出一个字符串
	 * @param list
	 * @return
	 */
	public static String compList(List<String> list, String separator){
		String result = null;
		if(list != null && !list.isEmpty()){
			StringBuilder tempBuilder = new StringBuilder();
			for(String s : list){
				tempBuilder.append(s).append(separator);
			}
			result = tempBuilder.substring(0, tempBuilder.length()-1);
			tempBuilder = null;
		}
		return result;
	}
	
	public static String[] list2Array(List<String> strList){
		if(strList == null || strList.isEmpty()) return new String[0];
		String[] result = new String[strList.size()];
		for(int i = 0 ; i < strList.size(); i++){
			result[i] = strList.get(i);
		}
		return result;
	}
	
	public static List<String> array2List(String[] strArray){
		if(strArray == null || strArray.length == 0) return new ArrayList<String>();
		List<String> result = new ArrayList<String>();
		for(String s : strArray){
			result.add(s);
		}
		return result;
	}
	
	public static boolean checkMap(Map map){
		if(null != map && map.size()>0){
			return true;
		}else{
			return false;
		}
	}
	
	public static boolean checkList(List list){
		if(null != list && list.size()>0){
			return true;
		}else{
			return false;
		}
	}
	
	public static String convert(String value, String defaultValue){
		return StringUtils.isNotBlank(value) ? value : defaultValue;
	}
	
	public static void main(String[] arg){
		System.out.println("111===="+UUID.randomUUID().toString());
	
		
//		Calendar cal = Calendar.getInstance();
//		cal.setTimeInMillis(1362644492823l);
//		System.out.println(DateFormatUtils.format(cal, "yyyy-MM-dd HH:mm:ss"));
	}
}
